Skip to main content

Introduction

AIH-Search utilizes OpenSearch engine. This means that queries are running in OpenSearch cluster and have the same structure as they have in OpenSearch (OpenSearch documentation).

Building the Query

Core query object#

The Query JSON has the following structure:

{   "query": QUERY_CLAUSE_HERE}

An empty search (i.e. {"query": {}}) is equivalent to a match_all query, which, as the name suggests, matches all documents.

See query clauses Query Clauses documentation.

bool clause#

All queries use the boolean query clause to combine each query clause. The base structure of the query will then always be the following:

{  "query": {    "bool": {          }  }}

Operator to query-clause location#

The two sub-clauses must_not and filter are used for the query-clauses. See the mapping table below, for where a query clause should be placed, based on the operator:

EqualsNot EqualsGT / GTE / LT / LTEContainsNot ContainsNullNot nullExistsNot exists
must_notxxxx
filterxxxxx

"Exists / Not Exists" with no sub-queries#

If the user does not provide any query clauses beneath an "Exists / Not Exists" row, then it must be understood as an "Any content / No content" query ("Exists / Not Exists" is only used on lists).

The bool part of the nested query should be replaced by the "match_all" : {} query.

Examples#

FieldOperatorValue
PopulationItemsNot Exists
{  "query": {    "bool": {      "must_not": [        {          "nested": {            "path": "PopulationItems",            "query": {              "match_all": {} <-- This is where the "bool" would normally be placed            }          }        }      ]    }  }}

Simple Query#

Ex. User has the following two rows in their query:

FieldOperatorValue
FailureModeNot Equals"Micro Pitting"
StartDate>13.01.2021

That would translate to the following query, where row 1 is in the must_not sub-clause and row 2 is in the filter sub-clause:

{  "query": {    "bool": {      "must_not": [        {          "terms": {            "FailureMode": [              "Micro Pitting"            ]          }        }      ],      "filter": [        {          "range": {            "startDate": {              "gt": "13.01.2021"            }          }        }      ]    }  }}

Null operator#

The null / not null operators are used to determine whether a field has been assigned a value.

Ex., the user wishes to find all deviations that have not been assigned a failure mode:

FieldOperatorValue
FailureModeNull

That would translate to the following query:

{  "query": {    "bool": {      "must_not": [        {          "exists": {            "field": "failureMode"          }        }      ]    }  }}